package com.lingx.model.impl.validator;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Component;

import com.lingx.model.IContext;
import com.lingx.model.IPerformer;
import com.lingx.model.impl.AbstractValidator;
import com.lingx.model.impl.DefaultField;
@Component
public class RegexValidator extends AbstractValidator {

	private static final long serialVersionUID = 2094588328378342183L;

	public RegexValidator() {
		super("RegexValidator", "正则验证");
		this.setComment("需要正则表达式");
	}

	@Override
	public boolean valid(Object value,String param,Map<String,Object> params,DefaultField code,IContext context)throws Exception {
		
		boolean b=true;
	    try {
			Pattern p = Pattern.compile(param);     
			Matcher m = p.matcher(value.toString());  
			b= m.matches();
		} catch (Exception e) {
			b=false;
		}
        return b;   
	}

}
